//
//  LLStatusRetweetView.swift
//  xinlangweibo
//
//  Created by 任玉林 on 16/6/29.
//  Copyright © 2016年 任玉林. All rights reserved.
//

import UIKit
import SnapKit

class LLStatusRetweetView: UIView {
    
    //记录约束
    var retweetViewBottomConstraint: Constraint?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    var status: LLStatusesModel?{
        didSet{
            
            contentLable.attributedText = status?.retweeted_status?.textAttr
            
            //判断是否有配图
            retweetViewBottomConstraint?.uninstall()
            if status?.retweeted_status?.pic_urls?.count > 0 {
                
                pictureView.hidden = false
                
                pictureView.pic_urls = status?.retweeted_status?.pic_urls
                
                self.snp_makeConstraints { (make) -> Void in
                    
                    retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(OriginalMargin).constraint
                }
            }else{
                
                pictureView.hidden = true
                
                self.snp_makeConstraints { (make) -> Void in
                    
                    retweetViewBottomConstraint = make.bottom.equalTo(contentLable).offset(OriginalMargin).constraint
                }
                
            }
        }
    }


    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


    private func setupUI(){
        
        addSubview(contentLable)
        addSubview(pictureView)
        
        //约束
        contentLable.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self).offset(OriginalMargin)
            
            make.leading.equalTo(self).offset(OriginalMargin)
        }
        
        //配图
        pictureView.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(contentLable.snp_bottom).offset(OriginalMargin)
            
            make.leading.equalTo(contentLable)
        }
        
        //给自己添加约束
        self.snp_makeConstraints { (make) -> Void in
            
           retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(OriginalMargin).constraint
        }
    }
    private lazy var contentLable:UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 15, maxWidth: SCREENW - 2 * OriginalMargin)
    
    private lazy var pictureView:LLPictureView  = LLPictureView()
        
    
}
